import { request } from '@/utils/axios';
import { User, LoginForm, RegisterForm, ApiResponse } from '@/types';
import { AxiosResponse } from 'axios';

// 用户相关API
export const userApi = {
  // 登录
  login: (data: LoginForm): Promise<AxiosResponse<ApiResponse<{ user: User; token: string }>>> =>
    request.post('/auth/login', data),
    
  // 注册
  register: (data: RegisterForm): Promise<AxiosResponse<ApiResponse<{ user: User; token: string }>>> =>
    request.post('/auth/register', data),
    
  // 获取用户信息
  getUserInfo: (): Promise<AxiosResponse<ApiResponse<User>>> =>
    request.get('/user/profile'),
    
  // 更新用户信息
  updateUserInfo: (data: Partial<User>): Promise<AxiosResponse<ApiResponse<User>>> =>
    request.put('/user/profile', data),
    
  // 登出
  logout: (): Promise<AxiosResponse<ApiResponse<null>>> =>
    request.post('/auth/logout'),
    
  // 刷新token
  refreshToken: (): Promise<AxiosResponse<ApiResponse<{ token: string }>>> =>
    request.post('/auth/refresh'),
};
